<!--{template common/header_ajax}-->
<!--{if $operation == 'editpermgroup'}-->
<form onsubmit="return false;">
    <div class="modal-header">
      <h4 class="modal-title text-truncate">{lang edit_folder_permissions}</h4>
      <button type="button" class="btn-close" data-dismiss="modal"></button>
    </div>
    <div class="modal-body">
        <div class="mb-3">
            <label for="pername" class="form-label">{lang folder_permission_name}</label>
            <input type="text" class="form-control" id="pername" name="pername" value="$groupperm[pername]"/>
          </div>
          <div class="row mb-3">
            <label class="col-sm-2">{lang choose_permission}</label>
            <div class="col-sm-10 gallery-grid">
              <!--{loop $perms $k $val}-->
                <div class="form-check form-check-inline gallery-item">
                    <input class="form-check-input" type="checkbox" name="perms[]" value="$val[1]"  id="inputval$val[1]"<!--{if $groupperm[perm] & $val[1]}--> checked="checked" <!--{/if}-->>
                    <label class="form-check-label" for="inputval$val[1]"><span class="{$val[2]} view-eidt perm_chk" data-perm="$val[1]"></span><span>$val[0]</span></label>
                </div>
                <!--{/loop}-->
            </div>
          </div>
    </div>
    <div class="modal-footer">
        <div class="proper-bottom" style="position: relative;">
            <div class="checkbox-custom">
                <input type="checkbox" class="form-check-input" name="default" value="1" id="inputdefault" <!--{if $groupperm['default']}-->checked="checked"
                <!--{/if}-->>
                <label for="inputdefault"><span class="proper-span">{lang set_default_permission_group}</span></label>
            </div>

        </div>
        <input type="hidden" name="id" value="$id"/>
        <input type="hidden" name="submit" value="true"/>
        <button type="button" class="btn btn-secondary" data-dismiss="modal">{lang cancel}</button>
        <button type="button" class="btn btn-primary" onclick="permedit(this.form)">{lang confirms}</button>
    </div>
</form>
<script type="text/javascript" reload="1">
    function permedit(form) {
        jQuery.post(MOD_URL+'&op=ajax&operation=editpermgroup', $(form).serialize(), function (data) {
            if (data['success']) {
                var perms = data['success']['perm'];
                var permstr = '';
                if (data['success']['default'] == 0) {
                    var defaultstr = '<span class="proper-perm proper-set" onclick="setDefault(this,' + data['success']['id'] + ')"><button type="button" class="btn btn-outline-primary btn-sm"><span class="mdi mdi-check perm-ok"></span>设为默认</button></span> ';
                } else {
                    var defaultstr = '<span class="proper-perm proper-default"><span class="mdi mdi-check perm-ok"></span>默认权限</span>';
                }
                var permoff = '';
                if (data['success']['off']) {
                    permoff = '<div class="form-check form-switch"><input type="checkbox" onchange="edit_perm(this,' + data['success']['id'] + ')" class="form-check-input"  /></div>';
                } else {
                    permoff = '<div class="form-check form-switch"><input type="checkbox" onchange="edit_perm(this,' + data['success']['id'] + ')" class="form-check-input" checked="checked" /></div>';
                    jQuery('.properties-list').each(function () {
                        var idval = jQuery(this).attr('id');
                        idval = idval.replace('perm_', '');
                        jQuery(this).find('.proper-delhover').html('<span class="proper-perm proper-set" onclick="setDefault(this,' + idval + ')"><button type="button" class="btn btn-outline-primary btn-sm"><span class="mdi mdi-check perm-ok"></span>设为默认</button></span>')

                    })
                }
                for (var o in perms) {
                    permstr += '<li class="nav-item"><span class="'+perms[o]+'" ></span></li>';
                }
                var html ='<tr class="properties-list lead" id="perm_'+data['success']['id']+'"> ' +
                      '<td>' +
                      '<img src="dzz/images/extimg/folder.png"><h6 class="d-inline-flex">'+data['success']['pername']+'</h6></td>'+
                      '<td><ul class="nav nav-pills text-primary">' +permstr+'</ul></td>' +
                      '<td>' +
                      '<div class="form-check form-switch"><input type="checkbox" onchange="edit_perm(this,'+data['success']['id']+')" class="form-check-input" checked="checked"/></div>' +
                      '</td>' +
                      '<td>' +
                      '<span class="mdi mdi-pencil lead dcolor" onclick="editpermgroup('+data['success']['id']+')" style="cursor:pointer;"></span> ' +
                      '<span class="mdi mdi-delete lead color-danger" onclick="delete_perm(this,'+data['success']['id']+')"></span>'+defaultstr+' ' +
                      '</td>' +
                      '</tr>';
                jQuery('#perm_' + data['success']['id']).replaceWith(html);
                var elem = jQuery('#perm_' + data['success']['id']).find('.js-switch');
                hideWindow('editpermgroup');
                showmessage('权限组编辑成功','success','3000',1);
            } else {
                showDialog(data['error']);
            }
        }, 'json').fail(function (jqXHR, textStatus, errorThrown) {
            showmessage('操作失败，请稍后再试: ' + textStatus, 'error', 3000, 1);
        });
    }
</script>
<!--{/if}-->
<!--{template common/footer_ajax}-->
